import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TreeNode } from '@iux/live';

@Component({
  selector: 'app-demo8',
  templateUrl: './demo8.component.html',
  styles: [
    `
      .treeselect-container {
        width: 3.68rem;
      }
    `,
  ],
})
export class Demo8Component implements OnInit {
  treeData: TreeNode[];
  selection: TreeNode[] = [];

  constructor(private http: HttpClient) {}

  ngOnInit() {
    this.initAsyncData();
  }

  initAsyncData() {
    this.http.get('assets/mockdata/tree.json', { params: { $prefix: 'none' } }).subscribe((res: any) => {
      this.treeData = res.options;
      this.selection = [this.treeData[1]];
    });
  }

  selectionChange(e) {
    console.log('selection:', e);
  }
}
